package public

import (
	"github.com/hwcer/cosgo/registry"
	"github.com/hwcer/yyds/context"
	"github.com/hwcer/yyds/errors"
	"server/game/cache"
	"server/share/config"
)

func init() {
	Register(&guide{})
}

type guide struct {
}

func (this *guide) Caller(node *registry.Node, handle *context.Context) interface{} {
	f := node.Method().(func(*guide, *context.Context) interface{})
	return f(this, handle)
}

/**
 * @name step
 * @param int val 值
 * 新手引导设置
 */

func (this *guide) Step(c *context.Context) interface{} {
	val := c.GetInt32("val")
	doc := cache.GetRole(c.Player.Updater)
	doc.Set("gs", val)
	return nil
}

/**
 * @name saveNoviceGuide
 * @param string groupId 引导分组ID
 * @param string sortId 排序ID
 * 存储新手引导
	//后续改变 todo

*/

func (this *guide) SaveNoviceGuide(c *context.Context) interface{} {
	groupId := c.GetInt32("groupId")
	sortId := c.GetInt32("sortId")

	if groupId == 0 || sortId == 0 {
		return errors.ErrArgEmpty
	}
	var exist bool
	for _, d := range config.Data.Novice {
		if d.NoviceGroup == groupId || d.NoviceSort == sortId {
			exist = true
			break
		}
	}
	if !exist {
		return errors.ErrConfigEmpty
	}
	//判断星光体等级
	//判断是否解锁关卡
	//新手引导而已，老子：不需要这么严格的判断，孔子：是的

	roleDoc := cache.GetRole(c.Player.Updater)
	roleAll := roleDoc.All()
	noviceGuide := roleAll.NoviceGuide
	if noviceGuide == nil {
		noviceGuide = map[int32]int32{}
	}
	noviceGuide[groupId] = sortId
	roleDoc.Set("noviceGuide", noviceGuide)
	return nil
}
